/*
package Final;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Insert {
    static javax.swing.JButton button_login = new javax.swing.JButton();
    static javax.swing.JButton button_cancle = new javax.swing.JButton();
    static JLabel labname = new JLabel();
    static JLabel labID = new JLabel();
    static JLabel labClass = new JLabel();
    static JLabel labSex = new JLabel();
    static JTextField textClass = new JTextField();
    static JLabel labAge = new JLabel();
    static JTextField textSex = new JTextField();
    static JTextField textAge = new JTextField();
    static JTextField textID = new JTextField();
    static JTextField textname = new JTextField();
    static JPanel jpan1 = new JPanel();
    public Insert() {
        JFrame jf = new JFrame();
        jf.add(jpan1);
        jf.setTitle("增加界面");
        jf.setSize(340, 500);
        //jf.setDefaultCloseOperation(3);
        jf.setLayout(new FlowLayout());
        jf.setLocationRelativeTo(null);
        jf.setResizable(false);

        java.awt.FlowLayout fl = new java.awt.FlowLayout(FlowLayout.CENTER, 5, 5);
        jf.setLayout(fl);

        java.awt.Dimension dim2 = new java.awt.Dimension(50, 20);//标签的大小
        java.awt.Dimension dim3 = new java.awt.Dimension(250, 30);//输入框的大小
        java.awt.Dimension dim4 = new java.awt.Dimension(70, 40);//按钮的大小

        //添加“学号”标签

        labname.setText("名字");
        labname.setPreferredSize(dim2);
        jpan1.add(labname);

        //添加账号输入框，并添加监控事件

        textname.setPreferredSize(dim3);
        jpan1.add(textname);

        //添加“学号”标签

        labID.setText("学号");
        labID.setPreferredSize(dim2);
        jpan1.add(labID);

        //添加账号输入框，并添加监控事件

        textID.setPreferredSize(dim3);
        jpan1.add(textID);



        //添加“班级”标签

        labClass.setText("班级");
        labClass.setPreferredSize(dim2);
        jpan1.add(labClass);


        textClass.setPreferredSize(dim3);
        jpan1.add(textClass);

        //添加“年龄”标签

        labAge.setText("年龄");
        labAge.setPreferredSize(dim2);
        jpan1.add(labAge);


        textAge.setPreferredSize(dim3);
        jpan1.add(textAge);

        //添加“性别”标签

        labSex.setText("性别");
        labSex.setPreferredSize(dim2);
        jpan1.add(labSex);


        textSex.setPreferredSize(dim3);
        jpan1.add(textSex);

        //添加一个登录按钮
//添加“籍贯”标签

        JLabel labOrigin = new JLabel();
        labOrigin.setText("籍贯");
        labOrigin.setPreferredSize(dim2);
        jpan1.add(labOrigin);

        JComboBox<String> cmb = new JComboBox<String>();
        cmb.addItem("河南郑州");
        cmb.addItem("河南开封");
        cmb.addItem("河南新乡");
        cmb.addItem("河南洛阳");
        //jc.addItemListener((ItemListener) this);
        jpan1.add(cmb);

        button_login.setText("添加");
        button_login.setPreferredSize(dim4);
        button_login.setBounds(10, 300, 300, 40);
        jpan1.add(button_login);


        button_cancle.setText("取消");
        button_cancle.setPreferredSize(dim4);
        button_cancle.setBounds(10, 300, 300, 40);
        jpan1.add(button_cancle);

        jf.setVisible(true);

        button_login.addActionListener(e -> {

            String sql2 = "insert into Student values(?,?,?,?,?,?)";
            Connection conn2 = Sql.open(); //连接数据库
            try {
//动态操作sql语句
                String city;
                city = cmb.getSelectedItem().toString();
                PreparedStatement pstmt = conn2.prepareStatement(sql2);
                pstmt.setString(1, textID.getText());
                pstmt.setString(2, textname.getText());
                pstmt.setString(3, textSex.getText());
                pstmt.setString(4, city);
                pstmt.setString(5, textClass.getText());
                pstmt.setString(6, textAge.getText());


                pstmt.executeUpdate();

            } catch (SQLException h) {

                h.printStackTrace();

            } finally {

                Sql.close(conn2); //关闭数据库

            }
            JFrame jFrame = new JFrame();
            jFrame.setTitle("成功界面");
            jFrame.setSize(340,100);
            jFrame.setDefaultCloseOperation(3);
            jFrame.setLayout(new FlowLayout());
            jFrame.setLocationRelativeTo(null);
            jFrame.setResizable(false);

            JLabel jLabel = new JLabel("添加成功！");
            JButton jButton = new JButton("返回");

            jButton.addActionListener(g -> {

                jFrame.dispose();

            });

            jFrame.add(jLabel);
            jFrame.add(jButton);
            jFrame.setVisible(true);
        });

        button_cancle.addActionListener(e -> {

            jf.dispose();

        });




    }


}
*/
